package com.example.accessdemo.config;

import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
//import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
//import java.util.Random;

@Configuration
public class MyAddressSource implements AddressSource {

    @Value("${rc.client.ip:localhost}")
    private String ip;
    
    @Value("${rc.client.port:8080}")
    private Integer port;
    
    @Override
    public ForestAddress getAddress(ForestRequest request) {
        // 定义 3 个 IP 地址
        //String[] ipArray = new String[] {
        //        "192.168.0.1",
        //        "192.168.0.2",
        //        "192.168.0.3",
        //};
        //// 随机选出其中一个
        //Random random = new Random();
        //int i = random.nextInt(3);
        //String ip = ipArray[i];
        // 返回 Forest 地址对象
        return new ForestAddress(ip, port);
    }
}
